import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Leet68 {
    public static void main(String[] args) {
        for (String s : fullJustify(new String[]{"Give","me","my","Romeo;","and,","when","he","shall","die,","Take","him","and","cut","him","out","in","little","stars,","And","he","will","make","the","face","of","heaven","so","fine","That","all","the","world","will","be","in","love","with","night","And","pay","no","worship","to","the","garish","sun."}, 25)) {
            System.out.println(s);
        }
    }
        static public List<String> fullJustify(String[] words, int maxWidth) {
            StringBuilder sb = new StringBuilder();
            List<String> list = new ArrayList<>();
            int t = maxWidth;
            int l = 0,r = -1;
            for (int i = 0; i < words.length; i++) {
                t-=words[i].length();
                if (i==0||i==r+1)
                    continue;
                if (t<=0||(i==words.length-1&&t-i+r+1<0)){
                    l = r+1;
                    r = i-1;
                    int len = t+words[i].length();
                    t = maxWidth;
                    if (r-l==0){
                        StringBuilder S = new StringBuilder(words[i-1]);
                        for (int j = 0; j < len; j++)
                            S.append(" ");
                        i--;
                        list.add(S.toString());
                        t = maxWidth;
                        continue;
                    }
                    while(true){
                        if(len/(r-l)==0){
                            r--;
                            i=i-1;
                            len = len+words[r+1].length();
                        }else break;
                    }
                    int ge = len/(r-l);
                    int duo = len%(r-l);
                    StringBuilder S = new StringBuilder();
                    for (int j = l; j < r; j++) {
                        S.append(words[j]);
                        if (duo>0){
                            for (int k = 0; k < ge+1; k++) {
                                S.append(" ");
                            }
                            duo--;
                        }else
                            for (int k = 0; k < ge; k++)
                                S.append(" ");
                    }
                    i--;
                    S.append(words[r]);
                    list.add(S.toString());
                }
            }
            StringBuilder sbb = new StringBuilder();
            for (int i = r+1; i < words.length; i++) {
                if (sbb.length()+words[i].length()>maxWidth)
                    break;
                sbb.append(words[i]);
                if (sbb.length()<maxWidth)
                    sbb.append(" ");
            }
            int zui = maxWidth-sbb.length();
            for (int i = 0; i < zui; i++) {
                sbb.append(" ");
            }
            list.add(sbb.toString());
            return list;
        }
}
